package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduCheckinRecordDTO;
import com.zenith.edu.po.vo.EduCheckinRecordVO;
import com.zenith.edu.service.EduCheckinRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/checkin-record")
@Tag(name = "签到记录管理", description = "签到记录管理接口")
public class EduCheckinRecordController {
    
    @Autowired
    private EduCheckinRecordService eduCheckinRecordService;
    
    @SecurePostMapping(value = "/createCheckinRecord",roles = {"ADMIN"},permission = "checkin-record:create")
    @Operation(summary = "创建签到记录")
    public Result<EduCheckinRecordVO> createCheckinRecord(@RequestBody EduCheckinRecordDTO dto) {
        EduCheckinRecordVO checkinRecordVO = eduCheckinRecordService.createCheckinRecord(dto);
        return Result.success(checkinRecordVO);
    }
    
    @SecurePostMapping(value = "/getCheckinRecordById",roles = {"ADMIN"},permission = "checkinRecord:read")
    @Operation(summary = "根据ID获取签到记录详情")
    public Result<EduCheckinRecordVO> getCheckinRecordById(@PathVariable Long id) {
        EduCheckinRecordVO checkinRecordVO = eduCheckinRecordService.getCheckinRecordById(id);
        if (checkinRecordVO == null) {
            return Result.fail("签到记录不存在");
        }
        return Result.success(checkinRecordVO);
    }
    
    @SecurePostMapping(value = "/updateCheckinRecord",roles = {"ADMIN"},permission = "checkinRecord:update")
    @Operation(summary = "更新签到记录信息")
    public Result<EduCheckinRecordVO> updateCheckinRecord(@RequestBody EduCheckinRecordDTO dto) {
        EduCheckinRecordVO checkinRecordVO = eduCheckinRecordService.updateCheckinRecord(dto);
        return Result.success(checkinRecordVO);
    }
    
    @SecurePostMapping(value = "/deleteCheckinRecord/{id}",roles = {"ADMIN"},permission = "checkinRecord:delete")
    @Operation(summary = "删除指定签到记录")
    public Result<Void> deleteCheckinRecord(@PathVariable Long id) {
        boolean result = eduCheckinRecordService.deleteCheckinRecord(id);
        if (!result) {
            return Result.fail("签到记录删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getCheckinRecordList",roles = {"ADMIN"},permission = "checkinRecord:read")
    @Operation(summary = "获取签到记录列表")
    public Result<List<EduCheckinRecordVO>> getCheckinRecordList() {
        List<EduCheckinRecordVO> checkinRecordList = eduCheckinRecordService.getCheckinRecordList();
        return Result.success(checkinRecordList);
    }
}